package com.njtoyo.taxi.admin.mapper.master.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.njtoyo.taxi.admin.library.Const;
import com.njtoyo.taxi.admin.mapper.master.entity.Ride;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author Dell
 * @since 2021-09-09
 */
@Repository
@DS(Const.PRIMARY_DS)
public interface RideMapper extends BaseMapper<Ride> {
    //查询车辆下的行程数
    Integer selectRideCount(Long id);

    @Select("SELECT * FROM ride WHERE id = (SELECT ride_id FROM ride_cancellation WHERE id = (SELECT cancel_id FROM cancellation_order WHERE user_id = #{customerId} AND state <> 2 ORDER BY created_at desc limit 1))")
    Ride getNonePayCancelOrderByCustomerId(@Param("customerId") Long customerId);

    @Select("(SELECT a.* FROM ride a WHERE a.category in (0,2) AND a.state IN (1,2,3,4) AND a.user_id = #{customerId} ORDER BY id DESC LIMIT 1) UNION (SELECT b.* FROM ride b WHERE b.category = 1 AND b.state IN (1,2,3,4) AND b.user_id = #{customerId} ORDER BY id DESC LIMIT 1) LIMIT 1")
    Ride getUndoneRideByCustomerId(@Param("customerId") Long customerId);







}
